iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 20
0
DevOps

Oops Step ( Home lab of a kind ) 系列 第 20

git 1 push 2 repo

  • 分享至 

  • xImage
  •  

如果git能在push的時候同時幫你做異地備份,豈不妙哉?打麻雀一砲雙響,打飛機純屬幻想。想男子漢大丈夫行不改名坐不改姓,如果要用不同名字左右開弓,這種事奉勸看官不要想,等後面git blame就會的自己多此一舉。

根據文件,重點只在於

git remote set-url --add --push origin https://gitserver/repository.git
git remote set-url --add --push origin ssh://git@gitserver:username/application.git/
git remote -v

那具體地說,該怎麼做呢?

那看看記錄,我從github增加一個gitlab

icekimo@Kris:~/Documents/KVM4e.g.$ git remote rename origin github
icekimo@Kris:~/Documents/KVM4e.g.$ git remote add gitlab git@gitlab.gis-tpe.com.tw:icekimo.chen/kvm-xml.git
icekimo@Kris:~/Documents/KVM4e.g.$ git push -u gitlab --all
The authenticity of host 'gitlab.gis-tpe.com.tw (118.163.30.44)' can't be established.
ECDSA key fingerprint is SHA256:CZ1+Y7JDlH70SAgKaUloegwh6JO+70NRjBOmm1j5sAY.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'gitlab.gis-tpe.com.tw,118.163.30.44' (ECDSA) to the list of known hosts.
Counting objects: 18, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (11/11), done.
Writing objects: 100% (18/18), 5.42 KiB | 5.42 MiB/s, done.
Total 18 (delta 9), reused 13 (delta 7)
To gitlab.gis-tpe.com.tw:icekimo.chen/kvm-xml.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'gitlab'.
icekimo@Kris:~/Documents/KVM4e.g.$ git push -u gitlab --tags
Everything up-to-date
icekimo@Kris:~/Documents/KVM4e.g.$

有圖為證,github

https://ithelp.ithome.com.tw/upload/images/20190918/20094403KiQLSFxhzQ.png

同樣資料複製到gitlab

https://ithelp.ithome.com.tw/upload/images/20190918/20094403ohdhCZdbn1.png
那麼設定檔長怎樣?

icekimo@Kris:~/Documents/KVM4e.g.$  cat .git/config
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "github"]
        url = git@github.com:August-Icekimo/KVM4e.g..git
        fetch = +refs/heads/*:refs/remotes/github/*
[branch "master"]
        remote = gitlab
        merge = refs/heads/master
[remote "gitlab"]
        url = git@gitlab.gis-tpe.com.tw:icekimo.chen/kvm-xml.git
        fetch = +refs/heads/*:refs/remotes/gitlab/*

但是這樣我們不滿足
我們無三不成禮,三人行必有我師焉,所以一定要變成三個 ,最重要的是不付錢
猜猜看下面這段要做什麼?

useradd git -d /home/git -m -s `which git-shell`
mkdir -p /srv/git/KVM-xml.git 
chown -R git:git /srv/git
cd /srv/git/KVM-xml.git && sudo -u git git --bare init

是七傷拳
https://ithelp.ithome.com.tw/upload/images/20190918/20094403SJ8LfatRni.png
歐,不是,是在本地建立一個git repo

為什麼要這樣做,是為了湊github、gitlab與gitolite的小宇宙在一點嗎?

因為我要路由器Bosley成就南方四賤客裡面千真之劍的梗,不懂的可以從這裡出去不要回來
但是技術上的難點就是,嵌入式裝置的dropbear ssh真的是太可怕的豬隊友了。
所以山不轉路轉,只需要很簡單的用rsync就弄好同步備份了啊?

icekimo@Kelly:/media/icekimo/0912682827/C7V5ROM/targets/ar71xx/generic$ scp -r packages/* icekimo@Bosley:/srv/ipk/ && ssj Bosley # 把程式包移到Bosley
icekimo@Bosley:~$ cd /srv/ipk/ && sudo opkg install linpopt* rsync*

然後我們來看看rsync表現如何

icekimo@Bosley:~$ rsync -art --progress --delete-after  icekimo@kris:/srv/git /srv
receiving file list ... 70 files to consider
git/
git/KVM-XML.git/
git/KVM-XML.git/HEAD
             23 100%   22.46kB/s    0:00:00 (xfr#1, to-chk=67/70)
git/KVM-XML.git/config
             66 100%   64.45kB/s    0:00:00 (xfr#2, to-chk=66/70)
git/KVM-XML.git/description
             73 100%   23.76kB/s    0:00:00 (xfr#3, to-chk=65/70)
git/KVM-XML.git/branches/
git/KVM-XML.git/hooks/
git/KVM-XML.git/hooks/applypatch-msg.sample
            478 100%  116.70kB/s    0:00:00 (xfr#4, to-chk=62/70)
git/KVM-XML.git/hooks/commit-msg.sample
            896 100%  145.83kB/s    0:00:00 (xfr#5, to-chk=61/70)
git/KVM-XML.git/hooks/fsmonitor-watchman.sample
          3,327 100%  249.92kB/s    0:00:00 (xfr#6, to-chk=60/70)
git/KVM-XML.git/hooks/post-update.sample
            189 100%   11.54kB/s    0:00:00 (xfr#7, to-chk=59/70)
git/KVM-XML.git/hooks/pre-applypatch.sample
            424 100%   18.00kB/s    0:00:00 (xfr#8, to-chk=58/70)
git/KVM-XML.git/hooks/pre-commit.sample
          1,642 100%   61.67kB/s    0:00:00 (xfr#9, to-chk=57/70)
git/KVM-XML.git/hooks/pre-push.sample
          1,348 100%   47.01kB/s    0:00:00 (xfr#10, to-chk=56/70)
git/KVM-XML.git/hooks/pre-rebase.sample
          4,898 100%  154.30kB/s    0:00:00 (xfr#11, to-chk=55/70)
git/KVM-XML.git/hooks/pre-receive.sample
            544 100%   16.10kB/s    0:00:00 (xfr#12, to-chk=54/70)
git/KVM-XML.git/hooks/prepare-commit-msg.sample
          1,492 100%   41.63kB/s    0:00:00 (xfr#13, to-chk=53/70)
git/KVM-XML.git/hooks/update.sample
          3,610 100%   92.77kB/s    0:00:00 (xfr#14, to-chk=52/70)
git/KVM-XML.git/info/
git/KVM-XML.git/info/exclude
            240 100%    5.86kB/s    0:00:00 (xfr#15, to-chk=50/70)
git/KVM-XML.git/objects/
git/KVM-XML.git/objects/02/
git/KVM-XML.git/objects/02/97834f6b8959089005308a174104098b3c7abd
            160 100%    3.63kB/s    0:00:00 (xfr#16, to-chk=47/70)
git/KVM-XML.git/objects/03/
git/KVM-XML.git/objects/03/0f42ef85c4a8455a3c94660799cd450b9c84df
          1,849 100%   39.25kB/s    0:00:00 (xfr#17, to-chk=45/70)
git/KVM-XML.git/objects/0f/
git/KVM-XML.git/objects/0f/cd3384e0129bd060c8c178622021e525b17541
            163 100%    3.25kB/s    0:00:00 (xfr#18, to-chk=43/70)
git/KVM-XML.git/objects/1c/
git/KVM-XML.git/objects/1c/b58df879d50c272927ff1a81222abe9ceac169
          1,451 100%   26.74kB/s    0:00:00 (xfr#19, to-chk=41/70)
git/KVM-XML.git/objects/1d/
git/KVM-XML.git/objects/1d/eb6d55b64120dc7a3165498f32219a73a99c9b
            136 100%    2.37kB/s    0:00:00 (xfr#20, to-chk=39/70)
git/KVM-XML.git/objects/69/
git/KVM-XML.git/objects/69/01e1aa3d6f9d3d395885da837f519f67d5d965
            160 100%    2.65kB/s    0:00:00 (xfr#21, to-chk=37/70)
git/KVM-XML.git/objects/69/867eb7c7ffc1a0f7e415cdd407c93518904531
            103 100%    1.65kB/s    0:00:00 (xfr#22, to-chk=36/70)
git/KVM-XML.git/objects/8e/
git/KVM-XML.git/objects/8e/0da2403a3222989de0518cd66f77bd5788f2e7
            198 100%    3.02kB/s    0:00:00 (xfr#23, to-chk=34/70)
git/KVM-XML.git/objects/97/
git/KVM-XML.git/objects/97/ad0b0be6ab1f07ae43f79d2f6e512f6383a590
            228 100%    3.32kB/s    0:00:00 (xfr#24, to-chk=32/70)
git/KVM-XML.git/objects/98/
git/KVM-XML.git/objects/98/47a9d00922adf047d5919665184c22c5e2315a
          1,149 100%   16.03kB/s    0:00:00 (xfr#25, to-chk=30/70)
git/KVM-XML.git/objects/a1/
git/KVM-XML.git/objects/a1/7ac0c4c1eac726d5d84f1607318d84deec6f35
          1,525 100%   20.68kB/s    0:00:00 (xfr#26, to-chk=28/70)
git/KVM-XML.git/objects/a5/
git/KVM-XML.git/objects/a5/7cc0f5a175900fa28c0123e23a52f59681f5d3
            228 100%    2.97kB/s    0:00:00 (xfr#27, to-chk=26/70)
git/KVM-XML.git/objects/a6/
git/KVM-XML.git/objects/a6/daef74b9a64c6e5a4a661e1cea2da36462eafd
          1,089 100%   13.81kB/s    0:00:00 (xfr#28, to-chk=24/70)
git/KVM-XML.git/objects/bd/
git/KVM-XML.git/objects/bd/1a4084b2e6923541dcc04b7fb2239528a1f4fd
            177 100%    2.16kB/s    0:00:00 (xfr#29, to-chk=22/70)
git/KVM-XML.git/objects/c4/
git/KVM-XML.git/objects/c4/073c2e97bf6d7718ecbaed9bdc71e045f2ef28
            200 100%    2.35kB/s    0:00:00 (xfr#30, to-chk=20/70)
git/KVM-XML.git/objects/f9/
git/KVM-XML.git/objects/f9/9c6522e23526496b6131a9aaa3a2faee58c2af
            179 100%    2.06kB/s    0:00:00 (xfr#31, to-chk=18/70)
git/KVM-XML.git/objects/fc/
git/KVM-XML.git/objects/fc/1d0c4c7345a071d89279152d2cea4bfbab8111
          1,707 100%   18.94kB/s    0:00:00 (xfr#32, to-chk=16/70)
git/KVM-XML.git/objects/fe/
git/KVM-XML.git/objects/fe/d01756b8f9f2ce4eca6018599697d7975faf8e
            142 100%    1.52kB/s    0:00:00 (xfr#33, to-chk=14/70)
git/KVM-XML.git/objects/info/
git/KVM-XML.git/objects/pack/
git/KVM-XML.git/refs/
git/KVM-XML.git/refs/heads/
git/KVM-XML.git/refs/heads/master
             41 100%    0.43kB/s    0:00:00 (xfr#34, to-chk=9/70)
git/KVM-XML.git/refs/remotes/
git/KVM-XML.git/refs/remotes/Kris/
git/KVM-XML.git/refs/remotes/Kris/master
             41 100%    0.41kB/s    0:00:00 (xfr#35, to-chk=6/70)
git/KVM-XML.git/refs/remotes/github/
git/KVM-XML.git/refs/remotes/github/HEAD
             41 100%    0.40kB/s    0:00:00 (xfr#36, to-chk=4/70)
git/KVM-XML.git/refs/remotes/github/master
             41 100%    0.39kB/s    0:00:00 (xfr#37, to-chk=3/70)
git/KVM-XML.git/refs/remotes/gitlab/
git/KVM-XML.git/refs/remotes/gitlab/master
             41 100%    0.38kB/s    0:00:00 (xfr#38, to-chk=1/70)
git/KVM-XML.git/refs/tags/
 0 files...
icekimo@Bosley:~$

/images/emoticon/emoticon04.gif是真的,就這樣而已

最後補充說明,如果要處理像虛擬機的磁碟映象檔備份,分成兩種類型
一種是像前面黑群暉介紹的loader的數位檔案,如果可以要先在.gitignore避開這類檔案
然後連結過去另一個目錄(耗用一個inode),在那裡改用git lfs管理,連美工.psd .ai .indd都可以考慮這樣

git lfs push --all https://github.com/user/new-repository.git

而剩下的就是超大硬碟檔,那個qemu-image本身就支援snapshot,所以就不用這樣辛苦。

到這裡的git奇巧淫技,是不是有讓維運團隊腦袋開始覺得

Yes

參考:
https://www.git-tower.com/learn/git/ebook/en/command-line/advanced-topics/git-lfs#start


上一篇
What else, KVM & QEMU?
下一篇
Meet the git, Sabrina?
系列文
Oops Step ( Home lab of a kind ) 34
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言